package OSMS.action.Boss;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import OSMS.dao.GoodsDao;
import OSMS.entity.Boss;


public class GoodsDeleteServlet extends HttpServlet {

	private GoodsDao dao = new GoodsDao();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Object boss_obj = session.getAttribute("boss");
		Boss boss = (Boss)boss_obj;
		int bid = boss.getBid();
		//因为goodslist页面向此处传了gid bid两个值，所以删除功能在未用session时便实现了bid的不丢失
		Object id1 = request.getParameter("gid");
		int gid = 0 ;
		if(id1 != null) {
			gid = Integer.parseInt(id1.toString());
		}
		
		
		boolean flag=false;
		try {
			 //调用dao方法删除对应的商品
			 flag = dao.deleteGoods(gid);
			 //删除后重新跳转回商品信息页面
		}catch(Exception e) {
			e.printStackTrace();
		}
		request.setCharacterEncoding("utf-8");	
		request.getRequestDispatcher("../boss/bossindex").forward(request, response);

	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
	
}
